<?php
/* 
 * The "main" file.
 * Calls for the different parts of the Squidler program.
 *
 * Author: Baron Gerarld S. Manzano
 * 
 */

include "sqparser.php";
include "sqcrawler.php";

set_time_limit(0);

$time0 = time();

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="sqstyle.css" />
<title>Squidler - A Squid Log Parser with Automatic Webpage Classifier</title>
</head>
<body class="main">

<?php

if(isset($_GET['generate'])){
	$parser = new SQParser();
	$size = $parser->getSize();
}

if(isset($parser)){

	echo '<div class="head">';
	echo '<table class="data">';
	echo '<tr>
		<th>IP Address</th>
		<th>Date</th>
		<th>Time</th>
		<th colspan="2">Webpage Visited</th>
		<th>Content Type</th>
		<th>Webpage Type</th>
	</tr>';
	echo '</table>
	</div>';
	echo '<div class="data">
	<table class="data">';

	for($c=0;$c<$size;$c++){
		if(($c % 2) == 0){
			echo '<tr class="odd">';
		}
		else{
			echo '<tr class="even">';
		}
		$out = $parser->getDataLine($c);
		echo '<td>' . $out[0] . "</td>";
		echo '<td>' . $out[1] . "</td>";
		echo '<td>' . $out[2] . "</td>";
		echo '<td colspan="2">' . $out[3] . "</td>";
		echo '<td>' . $out[4] . "</td>";
		
		if(strstr($out[4], "text")){
			$crawl = new SQCrawler($out[3], $c);
			echo '<td>' . $crawl->getClass() . '</td>';
			unset($crawl);
		}
		else{
			echo '<td>' . 'undefined' . '</td>';
		}
		echo "</tr>";
		
	}

	echo '</table></div>';

}

$time1 = time();
echo "<br /><p style='position:absolute;left:10%;up:80%;'>Elapsed time: " . ($time1 - $time0) . "</p>";

?>

</body>
</html>
